package com.lamatek.tags.google;

import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * GoogleMapWMSTag
 * 
 * Represents a &lt;googlemaps:wms> tag. Developers should not extend this class
 * or override it's methods.
 * 
 * @author Tom Cole
 * @version 0.92
 */
public class GoogleMapWMSTag extends TagSupport {
    
    String id = null;
    String name = null;
    String url = null;
    String layers = null;
    String srs = "EPSG:4326";
    String version = "1.1.1";
    String format = "image/jpeg";
    boolean showOnStartup = true;
    String pathToScript = null;
    boolean showOverlay = false;
    String copyright = "(c) Unknown";
    /**
     * Overrides doStartTag() from TagSupport. Developers should not override this method.
     */
    public int doStartTag() {
        Tag tag = this;
        while (tag.getParent() != null) {
            if (tag.getParent() instanceof GoogleMapTag) {
                ((GoogleMapTag) tag.getParent()).addWMSTag(this);
                return SKIP_BODY;
            }
            tag = tag.getParent();
        }
        return SKIP_BODY;
    }
    /**
     * Returns the desired image file format to retrieve from this WMS server.
     * 
     * @return The content-type for the desired image format.
     */
    public String getFormat() {
        return format;
    }
    /**
     * Sets the desired image type for images retrieved from this server. This value
     * must be a valid content-type.
     * 
     * @param format The desired content-type for images retrieved from this server.
     */
    public void setFormat(String format) {
        this.format = format;
    }
    /**
     * Returns the unique id for this WMS layer.
     * 
     * @return A unique id for this layer.
     */
    public String getId() {
        return id;
    }
    /**
     * Sets the unique id for this layer. Must be unique per map.
     * 
     * @param id A unique id for this layer.
     */
    public void setId(String id) {
        this.id = id;
    }
    /**
     * Returns the desired WMS layers to include in this map layer. These must be valid layer names
     * for the server referenced by the url. The layer names must be comma separated (without spaces).
     * 
     * @return A comma separated list of layer names.
     */
    public String getLayers() {
        return layers;
    }
    /**
     * Sets the comma separated list of layers to include in this map.
     * 
     * @param layers A comma separated list of vlaid layer names.
     */
    public void setLayers(String layers) {
        this.layers = layers;
    }
    /**
     * Returns the descriptive name for this layer.
     * 
     * @return A short name for this layer.
     */
    public String getName() {
        return name;
    }
    /**
     * Sets the descriptive name for this layer. This value is used as the
     * button label for this map type.
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * Denotes whether or not this map type should be initially selected on startup.
     * 
     * @return True if this maptype is to be initially selected. False if not.
     */
    public boolean isShowOnStartup() {
        return showOnStartup;
    }
    /**
     * Sets whether or not this map type should be initially selected on startup.
     * 
     * @param showOnStartup True or false.
     */
    public void setShowOnStartup(boolean showOnStartup) {
        this.showOnStartup = showOnStartup;
    }
    /**
     * Returns the WMS SRS set for this layer.
     * 
     * @return The desired srs.
     */
    public String getSrs() {
        return srs;
    }
    /**
     * Sets the WMS SRS for this map.
     * 
     * @param srs The desired SRS.
     */
    public void setSrs(String srs) {
        this.srs = srs;
    }
    /**
     * Returns the base URL to the WMS map server used to supply the tiles.
     * This url will include an ending ?.
     * 
     * @return A valid url to a WMS map server.
     */
    public String getUrl() {
        return url;
    }
    /**
     * Sets the base URL to the WMS server.
     * 
     * @param url A valid url to a WMS map server.
     */
    public void setUrl(String url) {
        if (url.indexOf("?") < 0)
            this.url = url + "?";
        else
            this.url = url;
    }
    /**
     * Returns the desired version. Default is 1.1.1
     * 
     * @return A valid WMS version number.
     */
    public String getVersion() {
        return version;
    }
    /**
     * Sets the desired version. Default is 1.1.1.
     * 
     * @param A valid WMS version number.
     */
    public void setVersion(String version) {
        this.version = version;
    }
    /**
     * Returns the path (either relative or absolute) to the 
     * wms1.js or wms2.js script required.
     * 
     * @return A relative or absolute path.
     */
    public String getPathToScript() {
        return pathToScript;
    }
    /**
     * Sets the path (either relative or absolute) to the 
     * wms1.js or wms2.js script required.
     * 
     * @param pathToScript A valid relative or absolute path.
     */
    public void setPathToScript(String pathToScript) {
        this.pathToScript = pathToScript;
    }
    /**
     * Denotes whether or not this map should show the hybrid overlay.
     * 
     * @return True or false.
     */
    public boolean isShowOverlay() {
        return showOverlay;
    }
    /**
     * Sets whether or not this map should also include the Google Map Hybrid overlay.
     * This feature is not available in version 2 maps.
     * 
     * @param showOverlay True to display the Hybrid Overlay, false if not.
     */
    public void setShowOverlay(boolean showOverlay) {
        this.showOverlay = showOverlay;
    }
    /**
     * Returns the copyright string that is displayed anytime this WMS mashup
     * is presented on the map.
     * 
     * @return Copyright string
     */
    public String getCopyright() {
        return copyright;
    }
    /** 
     * Sets the copyright string that is displayed anytime this WMS mashup
     * is presented on the map.
     * 
     * @param copyright A copyright string
     */
    public void setCopyright(String copyright) {
        this.copyright = copyright;
    }
}
